package user.controller;

import com.alibaba.fastjson2.JSON;
import core.constants.Constant;
import core.controller.BaseController;
import core.domain.Result;
import api.domain.vo.UserQuestionResultVO;
import core.threadLocal.ThreadLocalUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import user.domain.user.dto.UserSubmitDTO;
import user.service.IUserQuestionService;

@RequestMapping("/user/question")
@RestController
@Slf4j
public class UserQuestionController extends BaseController {

    @Autowired
    private IUserQuestionService userQuestionService;

    @PostMapping("/submit")
    public Result<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO) {
        log.info("UserQuestionController -> submit: userSubmitDTO {}", userSubmitDTO);
        return userQuestionService.submit(userSubmitDTO);
    }

    @PostMapping("/submit/mq")
    public Result<Void> submitMq(@RequestBody UserSubmitDTO userSubmitDTO) {
        log.info("UserQuestionController -> submitMq: userSubmitDTO {}", userSubmitDTO);
        return toResult(userQuestionService.submitMq(userSubmitDTO));
    }

    @GetMapping("/exe/result")
    public Result<UserQuestionResultVO> getExeResult(Long examId, Long questionId, String currentTime) {
        log.info("UserQuestionController -> getExeResult: examId: {}, questionId: {}, currentTime: {}", examId, questionId, currentTime);
        UserQuestionResultVO exeResult = userQuestionService.getExeResult(examId, questionId, currentTime);
        log.info("该接口返回为" + JSON.toJSONString(exeResult));
        return Result.success(exeResult);
    }
}